package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.UserResumeDAO;
import com.yang.doctorrecruitment.dto.EducationExperience;
import com.yang.doctorrecruitment.utils.NullChange;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class EducationExperienceAction extends ActionSupport {
    public EducationExperience educationexperience;

    public String EducationExperience(){
        int HighestEdu= educationexperience.getHighestEdu();
        String SchoolName=NullChange.NullChange(educationexperience.getSchoolName());
        String FinishTime=NullChange.NullChange(educationexperience.getFinishTime());
        String Major=NullChange.NullChange(educationexperience.getMajor());
        JSONObject json=new JSONObject();
        json.put("HighestEdu",HighestEdu);
        json.put("FinishTime",FinishTime);
        json.put("SchoolName",SchoolName);
        json.put("Major",Major);
        String jsonString =json.toJSONString();
        //保存

        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");
        boolean res= UserResumeDAO.updataEducationExperience(jsonString,UserID);
        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        if(res){

            request.setAttribute("tipMessage",1);
            return SUCCESS;
        }else{
            request.setAttribute("tipMessage",2);
            return ERROR;
        }

    }

    public EducationExperience getEducationexperience() {
        return educationexperience;
    }

    public void setEducationexperience(EducationExperience educationexperience) {
        this.educationexperience = educationexperience;
    }
}
